package cn.stylefeng.guns.czlm.controller;

import cn.stylefeng.guns.czlm.entity.TbCategory;
import cn.stylefeng.guns.czlm.service.TbCategoryService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/attr")
public class TbCategoryController {

    @Autowired
    private TbCategoryService tbCategoryService;


    @RequestMapping("/list")
    public @ResponseBody
    String attrList(HttpSession session) {
        Map<Integer,TbCategory> map = new HashMap();
        List<TbCategory> list=tbCategoryService.TbCategoryList();
        session.setAttribute("listTbCategory",list);
        for (TbCategory i: list) {
            map.put(i.getId(),i);
        }
        //JSONObject json =new JSONObject(map);
        String s= JSON.toJSONString(map);
        System.out.println(s);
       return s;
    }

    @RequestMapping("/")
    public @ResponseBody String t() {
        return null;
    }
}
